package com.jzo2o.customer.controller.consumer;

import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import com.rabbitmq.client.AMQP;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("consumerAddressBookController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 用户地址相关接口")
public class AddressBookController {

    @Autowired
    private IAddressBookService addressBookService;

    @GetMapping("/defaultAddress")
    @ApiOperation("查询用户默认地址值")
    public AddressBookResDTO findDefaultAddress(){
        return addressBookService.findDefaultAddress();
    }
    @PostMapping
    @ApiOperation("新增默认地址值")
    public void addAddress(@RequestBody AddressBookUpsertReqDTO addressBookUpsertReqDTO){
        addressBookService.addAddress(addressBookUpsertReqDTO);
    }
    @GetMapping("/page")
    @ApiOperation("地址簿列表分页查询")
    public PageResult<AddressBookResDTO> page(AddressBookPageQueryReqDTO dto) {
        return addressBookService.pageRequest(dto);
    }
    @GetMapping("/{id}")
    @ApiOperation("查询地址详细信息")
    public AddressBookResDTO getAddress(@PathVariable("id") Long id){
     return addressBookService.getAddress(id);
    }
    @PutMapping("/{id}")
    @ApiOperation("修改地址详细信息")
    public void putAddress(@PathVariable("id") Long id,@RequestBody AddressBookUpsertReqDTO dto){
         addressBookService.putAddress(id,dto);
    }
    @DeleteMapping("/batch")
    @ApiOperation("删除地址详细信息")
    public void deleteAddress(@RequestBody List<Long> ids){
        addressBookService.deleteAddress(ids);
    }
    @PutMapping("/default")
    @ApiOperation("设置默认地址")
    public void updateDefaultStatus(Long id,Integer flag){
        addressBookService.updateDefaultStatuss(id,flag);
    }
}